<template>
	<view class="BranchStore">
		<view class="BranchStoreBox">
			<view class="BranchStoreList">
				<view class="BranchStoreItem" v-for="(item,index) in list" :key="index" @click="toFoodDetails" :data-id="item.Shop.id">
					<view class="BranchStore_top">
						<view class="BranchStoreName">{{item.Shop.name}}</view>
						<image src="/static/index/phone.png" @click.stop="callPhone(item.Shop.mobile)" style="width: 50upx;height: 50upx;"></image>
						<!-- <u-icon name="phone-fill" color="#FFAC3F" size="50" @click.stop="callPhone(item.Shop.mobile)"></u-icon> -->
					</view>
					<view class="addressBox">
						<view class="address_L" @click.stop="openLocation" :data-index="index">
							<u-icon name="map" color="#FFAC3F" size="30"></u-icon>
							<view class="address">{{item.Shop.detailed_address}}</view>
						</view>
						<view class="addressNum">{{item.distance}}km</view>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[]
			}
		},
		onLoad() {
			this.list = uni.getStorageSync("groupStore");
		},
		methods: {
			toFoodDetails(e){
				let id = e.target.dataset.id || e.currentTarget.dataset.id;
				uni.navigateTo({
					url:"/pages/pagetwo/pages/FoodDetails/FoodDetails?id="+id
				})
			},
			openLocation(e){
				// #ifdef MP-WEIXIN
				app.$vm.checkAuth("scope.userLocation").then(result=>{
					if(result){
						let index = e.target.dataset.index || e.currentTarget.dataset.index;
						uni.openLocation({
							address:this.list[index].Shop.detailed_address,
							latitude:Number(this.list[index].Shop.dimension),
							longitude:Number(this.list[index].Shop.longitude)
						})
					}else{
						uni.showModal({
							title:"请检查系统定位和定位授权是否打开后重试"
						})
					}
				})
				// #endif
				// #ifdef APP
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				uni.openLocation({
					address:this.list[index].Shop.detailed_address,
					latitude:Number(this.list[index].Shop.dimension),
					longitude:Number(this.list[index].Shop.longitude)
				})
				// #endif
			},
			callPhone(phone){
				
				if(!phone){
					this.$refs.uToast.show({
						title:"暂未设置",
						type:"error",
						duration:2000
					})
					return false;
				}
				uni.makePhoneCall({
					phoneNumber:phone.trim()
				})
			}
		}
	}
</script>

<style scoped lang="less">
.BranchStore{
	background-color: #F3F3F3;
	height: 100vh;
	// padding-top: 140upx;
	overflow: auto;
	.BranchStoreBox{
		padding: 16upx 24upx;
		.BranchStoreList{
			.BranchStoreItem{
				width: 702upx;
				background: #FFFFFF;
				opacity: 1;
				border-radius: 8upx;
				padding: 32upx;
				margin-bottom: 16upx;
				.BranchStore_top{
					display: flex;
					justify-content: space-between;
					align-items: center;
					.BranchStoreName{
						font-size: 24upx;
						font-family: Source Han Sans CN;
						font-weight: bold;
						color: #333333;
					}
				}
				.addressBox{
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 24upx;
					font-size: 20upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #999999;
					.address_L{
						display: flex;
						align-items: center;
						.address{
							margin-left: 8upx;
						}
					}
					.addressNum{
						
					}
				}
			}
		}
	}
}
</style>
